const {client} = require('./elastic')
const { getLabelById } = require('../../common/model/feedback')

const indexTemp = { index:  { _index: 'feedback', _type: 'fb'} }

module.exports.save = async ({uid, keys, comment}) => {
	let indexes = []
	for(let key of keys) {
		indexes.push(indexTemp)
		indexes.push({
			uid,
			comment: getLabelById(key),
			type: 'option'
		})
	}
	indexes.push(indexTemp)
	indexes.push({
		uid,
		comment,
		type: 'manual'
	})
	client.bulk({
	  body: indexes
	}, function (err, resp) {
	  console.log(err)
	});
}
